//
//  KFDChatCell.m
//  KFD
//
//  Created by Lucky Luke on 8/16/15.
//  Copyright (c) 2015 kfd. All rights reserved.
//

#import "KFDChatCell.h"
#import "NSDate+format.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "TQRichTextView.h"
#import "ui_config.h"

@interface KFDChatCell ()

@property (weak, nonatomic) IBOutlet UIImageView *avatar;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (strong,nonatomic) TQRichTextView* contentTextView;

@end

@implementation KFDChatCell

- (void)awakeFromNib {
    // Initialization code
    self.avatar.layer.cornerRadius=self.avatar.bounds.size.width/2;
    self.avatar.layer.masksToBounds=YES;
    self.numLabel.layer.cornerRadius=3;
    self.numLabel.layer.masksToBounds=YES;
    self.contentLabel.hidden=YES;
    self.contentTextView=[[TQRichTextView alloc] initWithFrame:CGRectMake(47, 30, 200, 30)];
    self.contentTextView.font=[UIFont systemFontOfSize:13];
    self.contentTextView.backgroundColor=KFD_TRANSPARENT_COLOR;
    [self.contentView addSubview:self.contentTextView];
}

-(void)setChat:(KFDChat *)chat
{
    _chat=chat;
    NSString* avatarUrl=chat.face;
    if (avatarUrl&&avatarUrl.length>0) {
        [self.avatar sd_setImageWithURL:[NSURL URLWithString:avatarUrl] placeholderImage:[UIImage imageNamed:@"avatar"]];
    }
    self.nameLabel.text=chat.nickname;
    self.contentLabel.text=chat.lastmsg;
    self.contentTextView.text=chat.lastmsg;
    self.timeLabel.text=chat.lasttime.postFormat;
    if (chat.unreadnum>0) {
        self.numLabel.text=[NSString stringWithFormat:@"+%ld",(unsigned long)chat.unreadnum];
    }else{
        self.numLabel.hidden=YES;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
